package GUI;

import Business.PurchaseDetails_BS;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

public class PurchaseDetailsTableModel extends AbstractTableModel {

    String[] headers = {"ProductID", "Product Name", "Price", "Quantity", "Sub Total"};
    List<PurchaseDetails_BS> purchaseItems;
    

    public PurchaseDetailsTableModel() {
        purchaseItems = new ArrayList<PurchaseDetails_BS>();
    }

     public PurchaseDetails_BS getProduct(int rowIndex) {
        return  purchaseItems.get(rowIndex);
    }


    public int getRowCount() {
        return purchaseItems.size();
    }

    public int getColumnCount() {
        return headers.length;
    }

    @Override
    public String getColumnName(int column) {
        return headers[column];
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        PurchaseDetails_BS item = purchaseItems.get(rowIndex);

        switch (columnIndex) {
            case 0:
                return item.getProductId();
            case 1:
                return item.getProductName();
            case 2:
                return item.getPrice();
            case 3:
                return item.getQuantity();
            case 4:
                return item.getSubTotal();
        }

        return null;
    }

    public void addPurchaseItem(PurchaseDetails_BS item) {
        purchaseItems.remove(item);
        purchaseItems.add(item);
        fireTableDataChanged();
    }
    public void removePurchase(PurchaseDetails_BS pro) {
            purchaseItems.remove(pro);
            fireTableDataChanged();
        }

   
}
